<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="../js/jquery-3.6.0.min.js"></script>
    <script>

        function keypress2() {
            let text1 = document.getElementById("content").value;
            document.getElementById("content").value = text1.replaceAll(" ","");
        }


    </script>
</head>
<body>

自我介绍：
<div>
    <input id="content" onKeyUp="keypress2()" onblur="keypress2()"/>
</div>
<div id="msg">
    自动过滤字符串左右空格
</div>

</body>
</html>